///////////////////////////////////////////////////
/// tototoy Code
/// $Id: base.h 34 2009-10-10 13:29:43Z tonyjobmails $
/// $Date: 2009-10-10 13:29:43 +0000 (Sat, 10 Oct 2009) $
/// $Author: tonyjobmails $
/// $Revision: 34 $
/// E-mail: tonyjobmails@gmail.com
/// filename: base.h
/// function: 基本类型定义
///////////////////////////////////////////////////
#ifndef __BASE__H
#define __BASE__H

#include <string>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>

namespace base_type
{
	/// 基本数据类型
	typedef unsigned char _uint_8;
	typedef char _int_8;
	typedef unsigned short _uint_16;
	typedef short _int_16;
	typedef unsigned int _uint_32;
	typedef int _int_32;
	typedef unsigned long long _uint_64;
	typedef int long long _int_64;
}
namespace base_fun
{
	///////////////////////////////////////////////////////////////////
	/// 追加堆内在分配
	/// 使用时请保证pointer是使用new[]分配的堆，而非new分配的
	template<typename _T>
		static bool _in_new(_T* &pointer, unsigned int size, unsigned int in_size)
		{
			if(pointer && size)
			{
				_T *new_pointer = new _T[size + in_size];
				if(new_pointer)
				{
					memcpy(new_pointer, pointer, size * sizeof(_T));
					delete[] pointer;
					pointer = new_pointer;
					return true;
				}
			}
#ifdef _TONY_DEBUG
			std::cout << "_in_new失败, size=" << size << ", in_size=" << in_size << std::endl;
#endif
			return false;
		}
	///////////////////////////////////////////////////////////////////
	
	///////////////////////////////////////////////////////////////////
	/// 减少堆内在分配()
	/// 使用时请保证pointer是使用new[]分配的堆，而非new分配的
	template<typename _T>
		static bool _de_new(_T* &pointer, unsigned int size, unsigned int de_size)
		{
			if(pointer && size && size >= de_size)
			{
				if(size == de_size)
				{
					delete[] pointer;
					pointer = NULL;
					return true;
				}
				_T *new_pointer = new _T[size - de_size];
				if(new_pointer)
				{
					memcpy(new_pointer, pointer, (size - de_size) * sizeof(_T));
					delete[] pointer;
					pointer = new_pointer;
					return true;
				}
			}
#ifdef _TONY_DEBUG
			std::cout << "_de_new失败, size=" << size << ", de_size=" << de_size << std::endl;
#endif
			return false;
		}
	///////////////////////////////////////////////////////////////////
	
	int rand_between(int _min, int _max);
};

/// 定义华丽的分割线
void split_line(bool eng);

#endif
